package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import net.miginfocom.swing.MigLayout;

/**
 * A simple view to preview an email
 * 
 * @author MUSAB
 *
 * @version $Revision: 1.0 $
 */
public class EmailView extends JPanel {
	
	// fields
	private JTextField to, from, subject, dateTime;
	
	// textarea
	private JTextArea body;
	
	// close button
	private JButton closeBtn;
	
	
	/**
	
	 * @return the to */
	public JTextField getTo() {
		return to;
	}

	/**
	
	 * @return the from */
	public JTextField getFrom() {
		return from;
	}

	/**
	
	 * @return the subject */
	public JTextField getSubject() {
		return subject;
	}

	/**
	
	 * @return the dateTime */
	public JTextField getDateTime() {
		return dateTime;
	}

	/**
	
	 * @return the body */
	public JTextArea getBody() {
		return body;
	}

	public EmailView(){
		
		super(new MigLayout("fillx"));
		
		initComponents();
		setupComponents();
		
		closeBtn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				actionClose();
			}
		});
	}

	/**
	 * Closes the window
	 */
	protected void actionClose() {
		ViewHelpers.disposeParentDialog(this);
	}

	/**
	 * Setup the components in the view
	 */
	private void setupComponents() {

		this.add(new JLabel("To: "));
		this.add(to, "growx, wrap, width 300");
		
		this.add(new JLabel("From: "));
		this.add(from, "growx, wrap");
		
		this.add(new JLabel("Date/Time: "));
		this.add(dateTime, "growx, wrap");
		
		this.add(new JLabel("Subject: "));
		this.add(subject, "growx, wrap");
		
		this.add(body, "growx, span2, wrap, height 130");
		
		this.add(closeBtn, "skip 1, align right, push");
		
	}

	/**
	 * Initialize the components
	 */
	private void initComponents() {

		to = new JTextField();
		to.setEditable(false);
		
		from = new JTextField();
		from.setEditable(false);
		
		subject = new JTextField();
		subject.setEditable(false);

		dateTime = new JTextField();
		dateTime.setEditable(false);
		
		body = new JTextArea();
		body.setEditable(false);

		closeBtn = new JButton("Close", IconsManager.getImageIcon("small/cross.png"));
	}
	
}
